Do not create the console tty until domain_create_ring has succeeded. This
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Mon, 24 Oct 2005 13:11:07 +0000 (14:11 +0100)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Mon, 24 Oct 2005 13:11:07 +0000 (14:11 +0100)
means that any reads attempted on that tty will not cause handle_tty_read to
segfault looking for an interface that does not exist.

Move the writing of the tty node so that it happens after console/limit has
been read, as it is cleaner if the writing is the last thing that happens.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/console/daemon/io.c

index 60e89267fc00d1b22e86ee394bcb8f61d91c5b28..0b55607d50998ddd44184427210d55aacb1ba648 100644 (file)
@@ -163,14 +163,6 @@ static int domain_create_tty(struct domain *dom)
                        tcsetattr(master, TCSAFLUSH, &term);
                }
 
-               success = asprintf(&path, "%s/tty", dom->conspath) != -1;
-               if (!success)
-                       goto out;
-               success = xs_write(xs, NULL, path, slave, strlen(slave));
-               free(path);
-               if (!success)
-                       goto out;
-
                success = asprintf(&path, "%s/limit", dom->conspath) != -1;
                if (!success)
                        goto out;
@@ -180,6 +172,14 @@ static int domain_create_tty(struct domain *dom)
                        free(data);
                }
                free(path);
+
+               success = asprintf(&path, "%s/tty", dom->conspath) != -1;
+               if (!success)
+                       goto out;
+               success = xs_write(xs, NULL, path, slave, strlen(slave));
+               free(path);
+               if (!success)
+                       goto out;
        }
 
        return master;
@@ -269,6 +269,18 @@ static int domain_create_ring(struct domain *dom)
        }
        dom->local_port = rc;
 
+       if (dom->tty_fd == -1) {
+               dom->tty_fd = domain_create_tty(dom);
+
+               if (dom->tty_fd == -1) {
+                       err = errno;
+                       close(dom->evtchn_fd);
+                       dom->evtchn_fd = -1;
+                       dom->local_port = -1;
+                       goto out;
+               }
+       }
+
  out:
        return err;
 }
@@ -309,7 +321,7 @@ static struct domain *create_domain(int domid)
        dom->conspath = s;
        strcat(dom->conspath, "/console");
 
-       dom->tty_fd = domain_create_tty(dom);
+       dom->tty_fd = -1;
        dom->is_dead = false;
        dom->buffer.data = 0;
        dom->buffer.size = 0;